#region Using

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;

using Gizmox.WebGUI.Common;
using Gizmox.WebGUI.Forms;
using WaveMaster.Holidays.Club.Service;
using WaveMaster.Holidays.Club.Domain;
using System.Configuration;
using CrystalDecisions.Web;
using CrystalDecisions.CrystalReports.Engine;
using System.Collections;

#endregion

namespace WaveMaster.Holidays.Club.Web
{
    public partial class UserControlReportTravelAgentSummary : UserControl
    {
        TravelAgentService m_travelAgentService;

        User m_currentUser;
        MainForm m_mainForm;

        public UserControlReportTravelAgentSummary(string name, User user, MainForm mainForm)
        {
            InitializeComponent();
            Name = name;
            m_currentUser = user;
            m_mainForm = mainForm;
            m_travelAgentService = (TravelAgentService)ServiceFactory.Instance().GetService(ServiceFactory.TRAVEL_AGENT_SERVICE);
            initToolBarClick();
            initComboDataSource();
        }

        private void initComboDataSource()
        {
            ArrayList tas = new ArrayList();
            tas.Add(new TravelAgent(0, "ALL"));
            tas.AddRange(m_travelAgentService.LoadAllTravelAgent());
            comboBoxTravelAgent.DataSource = tas;
        }

        private void initToolBarClick()
        {
            toolBarButtonRunReport.Click += new EventHandler(toolBarButtonRunReport_Click);
        }

        void toolBarButtonRunReport_Click(object sender, EventArgs e)
        {
            TravelAgent ta = (TravelAgent)comboBoxTravelAgent.SelectedValue;
            DataSet result = m_travelAgentService.ReportTravelAgentSummary(ta.TravelAgentID);
            //test
            result.WriteXml(ConfigurationManager.AppSettings["ReportDataTemp"] + "ReportTravelAgentSummary" + m_currentUser.UserID + ".xml", XmlWriteMode.WriteSchema);
            htmlBox1.Url = ConfigurationManager.AppSettings["URLReport"] + "ReportViewer.aspx?ReportDataSource=ReportTravelAgentSummary" + m_currentUser.UserID + ".xml&ReportFile=ReportTravelAgentSummary.rpt";
            htmlBox1.Update();
            //test--------------------------

            //string reportID = ServiceFactory.GenerateRandomID().ToString();
            //Session["ReportTravelAgentSummaryData" + reportID] = result;
            //Session["ReportTravelAgentSummaryFile" + reportID] = "ReportTravelAgentSummary.rpt";
            //string param1 = "ReportFile=ReportTravelAgentSummaryFile" + reportID;
            //string param2 = "ReportDataSource=ReportTravelAgentSummaryData" + reportID;
            //htmlBox1.Url = ConfigurationManager.AppSettings["URLReport"] + "ReportViewer.aspx?" + param1 + "&" + param2;
            //htmlBox1.Update();
        }
    }
}